package listener;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.HttpServletRequest;

@WebListener
public class RequestListener implements ServletRequestListener{

    //初始化第n个请求
    int count = 0;

    @Override
    public void requestDestroyed(ServletRequestEvent sre) {
        System.out.println("第"+count+"个请求已销毁");
    }

    @Override
    public void requestInitialized(ServletRequestEvent sre) {

        //通过请求事件获取 HttpServletRequest 对象
        HttpServletRequest request = (HttpServletRequest) sre.getServletRequest();
        System.out.println("这是第"+(++count)+"个请求，URL："+request.getRequestURL());

    }
}
